feat(reference): compute_line_diff を LCS / Myers 化(Phase 4-B / Refs #191)#193
Merged
Conversation
SPEC #188 (Phase 3) で MVP として all-or-nothing 単一 hunk を返してい た compute_line_diff を similar クレートの TextDiff::from_slices ベ ースに置き換える。変更箇所のみを含む細粒度な Hunk のリストを返すよ うになり、reference diff の出力が局所化されて LLM context と人間レ ビューの両方で扱いやすくなる。 主な変更: - Cargo.toml に similar = "2" を追加 - src/reference/diff.rs::compute_line_diff: TextDiff::from_slices と iter_all_changes を歩く実装に置換。Insert / Delete の連続グループ を 1 Hunk にまとめ、Equal が来たら境界にする。before_start / after_start は変更開始行(1-indexed) - 既存テスト compute_line_diff_produces_single_hunk_for_changes を compute_line_diff_replacement_isolates_changed_lines に rename し て新挙動 (差分行のみ含む) に合わせる - 新規 RED テスト 3 件: inserts_only / deletes_only / separate_changes_produces_multiple_hunks - tasks/lessons.md に「2026-05-12 子 SPEC 増殖の防止」を追記して umbrella SPEC 下では新 SPEC を生やさないルールを言語化 ローカル検証: - cargo fmt -- --check: clean - cargo clippy --all-targets -- -D warnings: clean - cargo test --bin unity-cli: 382 passed / 0 failed - cargo llvm-cov --all-targets: TOTAL line coverage 90.94% - unity-cli skills lint --severity error: 15 skills / 0 violations Refs #191 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compute_line_diffをsimilarクレートの LCS / Myers ベース実装に置き換える。reference diff出力の LLM context 効率と人間レビューの可読性を改善する。Changes
Cargo.toml:similar = "2"を[dependencies]に追加 (v2.7.0)。src/reference/diff.rs::compute_line_diff:similar::TextDiff::from_slicesとiter_all_changesを歩く実装に置換。Insert/Deleteの連続グループを 1Hunkにまとめ、Equalが来たら境界とする。before_start/after_startは変更開始行(1-indexed)。src/reference/diff.rsのテスト:compute_line_diff_produces_single_hunk_for_changesをcompute_line_diff_replacement_isolates_changed_linesに rename して、新挙動(差分行のみ含む)に合わせて assertion を更新。compute_line_diff_for_inserts_only_returns_addition_hunk/compute_line_diff_for_deletes_only_returns_removal_hunk/compute_line_diff_for_separate_changes_produces_multiple_hunks。tasks/lessons.md: 「2026-05-12 子 SPEC 増殖の防止」を追記。umbrella SPEC が存在する Phase では新 SPEC を増やさず、Refsで commit / PR を umbrella に紐付けるルールを言語化。Testing
cargo fmt -- --check— cleancargo clippy --all-targets -- -D warnings— cleancargo test --bin unity-cli— 382 passed / 0 failedcargo llvm-cov --all-targets --summary-only -- --test-threads=1— TOTAL line coverage 90.94%unity-cli skills lint --severity error— 15 skills / 0 violationsClosing Issues
Refsのみ)Related Issues / Links
Checklist
cargo clippy,cargo fmt,unity-cli skills lint)tasks/lessons.mdへの運用ルール追記)Hunk構造を維持。出力の内容(含まれる行)が all-or-nothing から細粒度に変わるが、JSON スキーマは同じ。feat)Context
Phase 3 では
compute_line_diffを意図的に MVP として実装し、SPEC #188 の本文と PR #190 の Notes に「LCS / Myers 化は別 Issue として後追い可能」と明記していた。本 PR がその後追い実装で、reference diffの利用シナリオ(特に LLM が「特定 symbol の差分だけを context に入れる」用途)で発生していたbefore/afterの全行重複を解消する。Notes
similarクレートは Rust diff ライブラリのデファクト標準で、依存追加コストは限定的。compute_line_diffの LCS 化) だけを land する。残りの A (member-level) / C (C# lexer) / D (zip fallback) / E (vector embedding) は umbrella の Tasks を継続管理。tasks/lessons.mdの運用ルール追記は本 PR で導入したが、別 PR として切り出す方が clean な場合は revert + 再投入も可能。